package com.edward.service;


import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.edward.PagerModel;
import com.edward.model.ContractItem;

public class ContractItemManager extends HibernateDaoSupport {

	public void addContractItem(ContractItem contractItem) {
		
		getHibernateTemplate().save(contractItem);
	}
	
	public ContractItem getContractItem(int id){
		ContractItem w =(ContractItem)getHibernateTemplate().get(ContractItem.class, id);
		return w;
	}
	

	@SuppressWarnings("unchecked")
	public List<ContractItem> listContractItem() {
		return getHibernateTemplate().find("from ContractItem");
	}
	
	@SuppressWarnings("unchecked")
	public PagerModel pagerContractItem(int start,int limit,int id) {
		List <ContractItem>list = getHibernateTemplate().find("from ContractItem i  where CONTRACT_ID = " + id );
		int total = list.size();
		int toIndex = start + limit;
		if(toIndex>total){
			toIndex =  total;
		}
		List <ContractItem>datas = list.subList(start, toIndex);
		PagerModel pm = new PagerModel();
		pm.setTotal(total);
		pm.setDatas(datas);
		return pm;
		
	}
	
	
	public void updateContractItem(ContractItem item) {
	
		getHibernateTemplate().update(item);
	}
	
	public void deleteContractItem(int id){
		
		getHibernateTemplate().delete(getContractItem(id));
	}


}



